#include <iostream>
#include <string>
#include <stack>
using namespace std;
//string s1;

string be_numstr(string s1)   //to modify an initial string to string which only carries numbers and operators
{
    //int i;
    string s;
    for(int i=0;i<s1.length();i++){
        if((s1.at(i)>='0'&&s1.at(i)<='9')||(s1.at(i)=='.')||(s1.at(i)=='+')||(s1.at(i)=='-')||(s1.at(i)=='*')||(s1.at(i)=='(')||(s1.at(i)==')')||(s1.at(i)=='/')){
            s += s1.at(i);
        }
        //cout<<ch[i];     // for self-checking use
    }
    return s;
}

int check(string s1)     // to check whether the input is an error :if it is an error return 0, else return 1
{
    int flag=1,i,j=0;
    int count1=0,count2=0,index1[s1.length()],index2[s1.length()];          //count1 is for '(' , count2 is for ')' ; index1 and index2 are for checking the brackets be in order
    int all_operators[s1.length()];     //to record the indices of operators
    string ch=be_numstr(s1);
    
    // a preparation for checking the use of brackets
    for(i=0;i<s1.length();i++){
        if(ch[i]=='('){
            count1++;
            for(j=0;j<s1.length();j++){
                index1[j]=i;
            }
        }
        else if(ch[i]==')'){
            count2++;
            for(j=0;j<s1.length();j++){
                index2[j]=i;
            }
        }
    }
    /* 1 */ //the next of '(' is ')'
    if((count1!=0&&count2!=0)&&count1==count2){
    for(j=0;j<s1.length();j++){
        if(index1[j]>index2[j]){
            return flag=0;
        }
        else flag=1;
    }}
    else flag=1;
    
    /* 2 */ //consider there are no continuous operators
    for(i=0;i<s1.length();i++){
        if(ch[i]=='+'||ch[i]=='-'||ch[i]=='*'||ch[i]=='/'||ch[i]=='.'||ch[i]=='('||ch[i]==')'){
            all_operators[j]=i;
            j++;
        }
        for(int k=0;k<s1.length();k++){
            if(all_operators[k+1]-all_operators[k]==1){
                return flag=0;
            }
            else flag=1;}
    }
    /* 3 */ //consider the next operator of a dot is not a dot
    int dots_index[s1.length()],m=0;
    string operators;
    for(i=0;i<ch.length();i++){
        if((ch.at(i)=='.')||(ch.at(i)=='+')||(ch.at(i)=='-')||(ch.at(i)=='*')||(ch.at(i)=='(')||(ch.at(i)==')')||(ch.at(i)=='/')){
            operators += ch.at(i);
        }
    }
    for(int k=0;k<ch.length();k++){
        if(operators[k]=='.'){
            dots_index[m]=k;
            m++;
        }}
    for(int k=0;k<ch.length();k++){
        if(dots_index[k+1]-dots_index[k]==1){
            return flag=0;
        }
        else flag=1;
    }
    
    /* 4 */ //the first and last term cannot be those operators stated below respectively
    if(ch[0]=='+'||ch[0]=='*'||ch[0]=='/'||ch[0]=='.'||ch[0]==')')
    {
        return flag=0;
    }
    else if(ch[s1.length()-1]=='+'||ch[s1.length()-1]=='-'||ch[s1.length()-1]=='*'||ch[s1.length()-1]=='/'||ch[s1.length()-1]=='.'||ch[s1.length()-1]=='(')
    {
        return flag=0;
    }
    
    /* 5 */ //to determine whether the brackets are paired
    else if(count1!=count2)
    {
        return flag=0;
    }
    return flag=1;
}

int priority(char op){  //set the priority of operators
    int prio=0;
    switch(op){
        case '+':case '-': prio=1;break;
        case '*':case '/': prio=2;break;
        case '(':case ')': prio=3;break;
        default:break;
    }
    return prio;
}

void evaluate(){        //to evaluate the value of double
    stack<double> num;
    stack<char> op;
    double b=num.top();num.pop();
    double a=num.top();num.pop();
    char c=op.top();op.pop();
    double ans;
    switch(c){
        case '+':ans=a+b;break;
        case '-':ans=a-b;break;
        case '*':ans=a*b;break;
        case '/':
            if(b!=0){
                ans=a*1.0/b;break;
        }
            else cout<<"Invalid";
    }
    num.push(ans);
}


/*string be_postfix(string s){
    string postfix;
    
    return postfix;
} */



double calculate(string s)
{
    double ans=0;
    stack<string> S;
    string s2=be_numstr(s);
    if(check(s2)==0){
        return 0;
    }
    else{
      //  be_postfix(s);
        evaluate();
    }
    
    return ans;
}

int main() {
    string s1;
    cin>>s1;
    cout<<"The string in number is: ";
    cout<<be_numstr(s1)<<endl;
    cout<<"Is it an Error ? Ans: ";
    if(check(be_numstr(s1))==0){
        cout<<"Yes,it is an error."<<endl;
        return 0;
    }
    else {
        cout<<"No,it is correct."<<endl;
        cout<<"The answer is: ";
        cout<<calculate(s1);
    }
    return 0;
}

